#include <bits/stdc++.h>

const int MAXN = 200005;
const int LOGN = 50;
const int INF  = 1e9;

using namespace std;

int N, M, K;

namespace SegTree1 {
	struct Node {
		int lc, rc;
		int Min = INF;
	} T[MAXN * LOGN];
	
	#define LC T[x].lc
	#define RC T[x].rc
	
	inline int Cnt = 0;
	
	inline void Maintain (const int x) {
		T[x].Min = min (T[LC].Min, T[RC].Min);
	}
	
	inline void Ins (const int p, const int v, int &x, const int L = 1, const int R = M) {
		if (!x) x = ++ Cnt;
		if (L == R) return T[x].Min = min (T[x].Min, v), void ();
		int M = (L + R) >> 1;
		if (p <= M) Ins (p, v, LC, L, M);
		else Ins (p, v, RC, M + 1, R);
		Maintain (x);
	}
	
	inline int  Min (const int l, const int r, const int x, const int L = 1, const int R = M) {
		if (!x) return INF;
		if (l >  R || L >  r) return INF;
		if (l <= L && R <= r) return T[x].Min;
		int M = (L + R) >> 1;
		return min (Min (l, r, LC, L, M), Min (l, r, RC, M + 1, R));
	}
	
	#undef LC
	#undef RC
}

namespace SegTree2 {
	struct Node {
		int RT;
	} T[MAXN << 2];
	
	#define LC (x << 1)
	#define RC (x << 1 | 1)
	
	inline void Ins (const int p, const int q, const int v, const int x = 1, const int L = 1, const int R = N) {
		SegTree1::Ins (q, v, T[x].RT);
		if (L == R) return ;
		int M = (L + R) >> 1;
		if (p <= M) Ins (p, q, v, LC, L, M);
		else Ins (p, q, v, RC, M + 1, R);
	}
	
	inline int  Min (const int xl, const int xr, const int yl, const int yr, const int x = 1, const int L = 1, const int R = N) {
		if (xl > N || xr < 1 || yl > M || yr < 1) return INF ;
		if (xl <= L && R <= xr) return SegTree1::Min (yl, yr, T[x].RT);
		if (xl >  R || L >  xr) return INF;
		int M = (L + R) >> 1;
		return min (Min (xl, xr, yl, yr, LC, L, M), Min (xl, xr, yl, yr, RC, M + 1, R));
	}
}

using namespace SegTree2;

char Mp[MAXN];

inline int G (const int x, const int y) {
	return x * M + y;
}

struct Point {
	int x, y;
} Sr, De;

int Ans[MAXN];

inline void Print () {
	for (int i = 1; i <= N; ++ i)
		for (int j = 1; j <= M; ++ j)
			cerr << Ans[G (i, j)] << " \n" [j == M];
}

inline void BFS () {
	queue <Point> Q;
	Q.push (Sr);
	
	int xl, xr, yl, yr, xL, xR, yL, yR, A;
	Point Now;
	
	while (!Q.empty ()) {
		Now = Q.front (), Q.pop ();
		
		xl = max (1, Now.x - K + 1);
		xr = min (N, Now.x + K - 1);
		yl = max (1, Now.y - K + 1);
		yr = min (M, Now.y + K - 1);
		xL = max (1, Now.x - K);
		xR = min (N, Now.x + K);
		yL = max (1, Now.y - K);
		yR = min (M, Now.y + K);
		
	//	cerr << xl << ' ' << xr << '\n';
		
		A  = min (Min (xl, xr, yL, yR), Min (xL, xR, yl, yr)) + 1;
		if (Mp[G (Now.x, Now.y)] != '#') {
			if (Now.x > 1) A = min (A, Ans[G (Now.x - 1, Now.y)]);
			if (Now.x < N) A = min (A, Ans[G (Now.x + 1, Now.y)]);
			if (Now.y > 1) A = min (A, Ans[G (Now.x, Now.y - 1)]);
			if (Now.y < M) A = min (A, Ans[G (Now.x, Now.y + 1)]);
		}
		
	//	cerr << Now.x << ' ' << Now.y << ' ' << xL << ' ' << xR << ' ' << yL << ' ' << yR << ' ' << A << '\n';
		
		if (Now.x == Sr.x && Now.y == Sr.y) A = 0;
		
		if (A >= Ans[G (Now.x, Now.y)]) continue ;
		
		Ins (Now.x, Now.y, A), Ans[G (Now.x, Now.y)] = A;
		
		if (Now.x > 1) Q.push ({Now.x - 1, Now.y});
		if (Now.x < N) Q.push ({Now.x + 1, Now.y});
		if (Now.y > 1) Q.push ({Now.x, Now.y - 1});
		if (Now.y < M) Q.push ({Now.x, Now.y + 1});
		
	//	cerr << '\n' << Now.x << ' ' << Now.y << " Ques " << Q.size () << '\n';
	//	Print ();
	}
	
}

int main () {
	
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	
	freopen ("stamp.in", "r", stdin);
	freopen ("stamp.out", "w", stdout);
	
	cin >> N >> M >> K;
	
	cin >> Sr.x >> Sr.y >> De.x >> De.y;
	
	for (int i = 1; i <= N; ++ i)
		for (int j = 1; j <= M; ++ j)
			cin >> Mp[G (i, j)], Ans[G (i, j)] = INF;
		
	BFS ();
	
	cout << Ans[G (De.x, De.y)] << '\n';
	
	return 0;
}
